import store from "@/store/index";
import $t from "@/z/function/$t";
let test = uni.$u.test;
let defaultValue = uni.$z.defaultValue;
// import userStore from "@/store/modules/user";
let request = uni.$z.request;
// import requestStore from "@/store/modules/request";
let timefn = uni.$z.timefn;
let StationType = defaultValue.StationType;
let deepClone = uni.$u.deepClone;

// const requeststore = requestStore();
// const userstore = userStore();
let requeststore = {
	async getRequest(url, data) {
		return store.dispatch("request/getRequest", {
			url,
			data,
		});
	},
};
let userstore = store.state.user;
const ChargeCarsearchjson = [{
		label: $t("设备ID"),
		value: "gtel",
	},
	{
		label: $t("设备名称"),
		value: "mc",
	},
	{
		label: $t("设备状态"),
		value: "gzt",
		type: "select",
		option: [{
			label: $t("全部"),
			value: ""
		}, ...defaultValue.gzt],
	},
	{
		label: $t("所属站点"),
		value: "pcs",
		type: "pcs",
	},

	{
		label: $t("收费模式"),
		value: "type",
		type: "select",
		option: [{
			label: $t("全部"),
			value: ""
		}, ...defaultValue.type],
		defaultValue: "",
	},
	{
		label: $t("设备类型"),
		value: "xtype",
		type: "select",
		option: [{
			label: $t("全部"),
			value: ""
		}, ...defaultValue.xtype],
	},
];
// gtype: gtype in (0,1,5,6,7,8,11,12,101,3)
const ChargeCartypes = [
	function({
		formData
	}) {
		const type = {
			label: $t("收费模式"),
			value: "type",
			type: "select",
			defaultValue: "1",
		};
		let option = defaultValue.type;
		if (formData.gtype == "51") {
			option = [{
					label: $t("充电柜租置"),
					value: "11",
				},
				{
					label: $t("阶梯退费"),
					value: "8",
				},
			];
			type.defaultValue = "11";
		} else if (
			formData.gtype == "10" ||
			(formData.gtype == "2" && formData.b_ask != "1")
		) {
			option = defaultValue.type.filter((e) => {
				return ["0", "1", "2"].some((f) => {
					return f == e.prop;
				});
			});
		} else if (formData.gtype == "2" && formData.b_ask == "1") {
			option = defaultValue.type.filter((e) => {
				return ["0", "1", "2"].some((f) => {
					return f == e.prop;
				});
			});
			option.push({
				label: $t("阶梯电量"),
				value: "12",
			}, {
				label: $t("地锁阶梯电量计费"),
				value: "14",
			});
			type.defaultValue = "1";
		} else if (formData.gtype == "52") {
			option = [{
				label: $t("地锁阶梯电量计费"),
				value: "14",
			}, ];
			type.defaultValue = "14";
		} else if (formData.gtype == "61" || formData.gtype == "62") {
			option = [
				...defaultValue.type.filter((e) => {
					return ["1"].some((f) => {
						return f == e.prop;
					});
				}),
				{
					label: $t("阶梯电量"),
					value: "12",
				},
				{
					label: $t("地锁阶梯电量计费"),
					value: "14",
				},
			];
			type.defaultValue = "1";
		} else if (formData.gtype == "63") {
			option = [
				...defaultValue.type.filter((e) => {
					return ["1"].some((f) => {
						return f == e.prop;
					});
				}),
			];
		}

		type.option = option;
		return [type];
	},
	function({
		formData
	}) {
		if (formData.type != 1) {
			return [];
		}
		const r = [{
			label: $t("电费单价"),
			value: "df",
			dw: "元/度",
			defaultValue: "100",
			fl: 100,

			rules: [{
				required: true,
				message: $t("电费单价错误"),
				trigger: "blur",
				validator(_rule, value, callback) {
					if (!test.amount(value)) {
						callback(new Error("error"));
					} else {
						callback();
					}
				},
			}, ],
		}, ];
		return r;
	},
	function({
		formData
	}) {
		if (formData.type != 2) {
			return [];
		}
		const r = [{
				label: $t("充电时长"),
				value: "df",
				dw: $t("分钟/1元"),
				defaultValue: "240",
				rules: [{
					required: true,
					message: $t("充电时长错误"),
					trigger: "blur",
					validator(_rule, value, callback) {
						if (!test.digits(value)) {
							callback(new Error("error"));
						} else {
							callback();
						}
					},
				}, ],
			},
			{
				label: $t("刷卡时长"),
				value: "jebd",
				dw: t("分钟/1元"),
				defaultValue: "240",
				rules: [{
					required: true,
					message: $t("刷卡时长错误"),
					trigger: "blur",
					validator(_rule, value, callback) {
						if (!test.digits(value)) {
							callback(new Error("error"));
						} else {
							callback();
						}
					},
				}, ],
			},
		];
		if (formData.gtype != "51") {
			r.push({
				label: $t("最低费用"),
				value: "qbf",
				dw: "元",
				defaultValue: "0",
				fl: 100,
				rules: [{
					required: true,
					message: $t("最低费用错误"),
					trigger: "blur",
					validator(_rule, value, callback) {
						if (!test.amount(value)) {
							callback(new Error("error"));
						} else {
							callback();
						}
					},
				}, ],
			});
		}
		return r;
	},
	function({
		formData
	}) {
		if (formData.type != 3) {
			return [];
		}
		const r = [];
		if (formData.gtype != "51") {
			r.push({
				label: $t("最低费用"),
				value: "qbf",
				dw: $t("元"),
				defaultValue: "0",
				fl: 100,
				rules: [{
					required: true,
					message: $t("最低费用错误"),
					trigger: "blur",
					validator(_rule, value, callback) {
						if (!test.amount(value)) {
							callback(new Error("error"));
						} else {
							callback();
						}
					},
				}, ],
			});
		}

		r.push({
			label: $t("添加档数"),
			type: "StepControl",
			min: 4,
			max: 8,
			span: 24,
			children: [{
					label: $t(`${0}档瓦数`),
					value: "a{0}",
					dw: "W",
					defaultValue: [
						"200",
						"350",
						"600",
						"900",
						"1500",
						"2000",
						"3000",
						"4000",
					],
					type: "typew",
					prepend: ({
						formData,
						item
					}) => {
						// console.log(formData, item);
						// 从item.prop中获取当前档数
						const index = item.prop.match(/\d+/)[0];
						if (index == 1) {
							return `0 W ~ `;
						}
						return `${formData[`a${index - 1}`]} W ~ `;
					},
				},
				{
					label: $t("{0}档充电时长"),
					value: "df{0}",
					dw: t("分钟/1元"),
					defaultValue: ["240", "180", "120", "60", "50", "40", "30", "20"],
				},
			],
		});
		return r;
	},
	function({
		formData
	}) {
		if (formData.type != 4) {
			return [];
		}
		const r = [];
		r.push({
			label: $t("充电时长"),
			value: "df",
			dw: t("分钟/1元"),
			defaultValue: "240",
			rules: [{
				required: true,
				message: $t("充电时长错误"),
				trigger: "blur",
				validator(_rule, value, callback) {
					if (!test.digits(value)) {
						callback(new Error("error"));
					} else {
						callback();
					}
				},
			}, ],
		}, {
			label: $t("超时费用"),
			value: "dfsj",
			dw: "元/时",
			defaultValue: "50",
			fl: "100",
			rules: [{
				required: true,
				message: $t("超时费用错误"),
				trigger: "blur",
				validator(_rule, value, callback) {
					if (!test.amount(value)) {
						callback(new Error("error"));
					} else {
						callback();
					}
				},
			}, ],
		});
		return r;
	},
	function({
		formData
	}) {
		if (formData.type != 5) {
			return [];
		}
		const r = [];
		r.push({
			label: $t("刷卡时长"),
			value: "jebd",
			dw: $t("小时"),
			defaultValue: "1",
		}, {
			label: $t("费用"),
			value: "df",
			dw: $t("元/时"),
			defaultValue: "30",
			fl: 100,
			rules: [{
				required: true,
				message: $t("费用错误"),
				trigger: "blur",
				validator(_rule, value, callback) {
					if (!test.amount(value)) {
						callback(new Error("error"));
					} else {
						callback();
					}
				},
			}, ],
		});
		return r;
	},
	function({
		formData
	}) {
		if (formData.type != 6) {
			return [];
		}
		const r = [{
			label: $t("刷卡时长"),
			value: "jebd",
			dw: $t("小时"),
			defaultValue: "1",
		}, ];

		r.push({
			label: $t("添加档数"),
			type: "StepControl",
			min: 4,
			max: 8,
			span: 24,
			children: [{
					label: $t(`${0}档瓦数`),
					value: "a{0}",
					dw: "W",
					defaultValue: [
						"200",
						"350",
						"600",
						"900",
						"1500",
						"2000",
						"3000",
						"4000",
					],
					type: "typew",
					prepend: ({
						formData,
						item
					}) => {
						// console.log(formData, item);
						// 从item.prop中获取当前档数
						const index = item.prop.match(/\d+/)[0];
						if (index == 1) {
							return `0 W ~ `;
						}
						return `${formData[`a${index - 1}`]} W ~ `;
					},
				},
				{
					label: $t("{0}档时长"),
					value: "df{0}",
					dw: $t("元/时"),
					fl: 100,
					defaultValue: ["30", "40", "50", "60", "70", "80", "90", "100"],
				},
			],
		});
		r.push({
			label: $t("小时退费"),
			value: "b_tk",
			defaultValue: "0",
			type: "select",
			option: [{
					label: $t("不退费"),
					value: "0"
				},
				{
					label: $t("退费"),
					value: "1"
				},
			],
		});

		return r;
	},
	function({
		formData
	}) {
		if (formData.type != 7) {
			return [];
		}
		const r = [{
				label: $t("刷卡时长"),
				value: "jebd",
				dw: $t("小时"),
				defaultValue: "1",
			},
			{
				label: $t("费用"),
				value: "df",
				dw: $t("元/时"),
				defaultValue: "30",
				fl: 100,

				rules: [{
					required: true,
					message: $t("费用错误"),
					trigger: "blur",
					validator(_rule, value, callback) {
						if (!test.amount(value)) {
							callback(new Error("error"));
						} else {
							callback();
						}
					},
				}],
			},
		];

		return r;
	},
	function({
		formData
	}) {
		if (formData.type != 8) {
			return [];
		}
		const r = [];
		if (formData.gtype != "51") {
			r.push({
				label: $t("最低费用"),
				value: "qbf",
				dw: $t("元"),
				defaultValue: "0",
				fl: 100,
				rules: [{
					required: true,
					message: $t("最低费用错误"),
					trigger: "blur",
					validator(_rule, value, callback) {
						if (!test.amount(value)) {
							callback(new Error("error"));
						} else {
							callback();
						}
					},
				}, ],
			});
		}
		r.push({
			label: $t("添加档数"),
			type: "StepControl",
			min: 4,
			max: 8,
			span: 24,

			children: [{
					label: $t(`${0}档瓦数`),
					value: "a{0}",
					dw: "W",
					defaultValue: [
						"200",
						"350",
						"600",
						"900",
						"1500",
						"2000",
						"3000",
						"4000",
					],
					type: "typew",
					prepend: ({
						formData,
						item
					}) => {
						// console.log(formData, item);
						// 从item.prop中获取当前档数
						const index = item.prop.match(/\d+/)[0];
						if (index == 1) {
							return `0 W ~ `;
						}
						return `${formData[`a${index - 1}`]} W ~ `;
					},
				},
				{
					label: $t("{0}档充电时长"),
					value: "df{0}",
					dw: t("分钟/1元"),
					defaultValue: ["240", "180", "120", "60", "50", "40", "30", "20"],
				},
			],
		}, {
			label: $t("退款精度"),
			value: "df",
			defaultValue: "0",
			type: "select",
			option: [{
					label: $t("精确到角"),
					value: "0"
				},
				{
					label: $t("精确到分"),
					value: "1"
				},
			],
		}, {
			label: $t("退款时间"),
			value: "dfsj",
			defaultValue: "60",
			if: {
				zhi: [{
					value: "type",
					zhi: ["8"]
				}],
			},
			dw: $t("分"),
			rule: [{
				required: true,
				message: $t("退款时间不能低于十分钟"),
				trigger: "blur",
				validator(_rule, value, callback) {
					if (Number(value) < 10) {
						callback(new Error("error"));
					} else {
						callback();
					}
				},
			}, ],
		});
		if (formData.gtype != "51") {
			r.push({
				label: $t("保底金额"),
				value: "jebd",
				defaultValue: "0",
				fl: "100",
				dw: $t("元"),
			});
		} else {
			r.push({
				label: $t("租置费用"),
				value: "qbf",
				defaultValue: "0",
				fl: "100",
				dw: $t("元/小时"),
			}, {
				label: $t("免费时长"),
				value: "jebd",
				defaultValue: "0",
				dw: $t("分"),
			});
		}
		return r;
	},
	function({
		formData
	}) {
		if (formData.type != 9) {
			return [];
		}
		const r = [];
		const adefaultarray = ["100", "200", "0", "0"];
		const dfdefaultarray = ["180", "480", "0", "0"];
		for (let index = 1; index <= 4; index++) {
			r.push({
				label: `${index}${$t("档费用")}`,
				value: `a${index}`,
				defaultValue: adefaultarray[index - 1],
				fl: "100",
				dw: $t("元"),
				span: 8,
			}, {
				label: "/",
				value: `df${index}`,
				defaultValue: dfdefaultarray[index - 1],
				dw: $t("分钟"),
				span: 4,
				labelwidth: "auto",
			});
		}
		return r;
	},
	function({
		formData
	}) {
		if (formData.type != 10) {
			return [];
		}
		const r = [{
				label: $t("电费单价"),
				value: "df",
				dw: $t("元/度"),
				defaultValue: "100",
				fl: 100,

				rules: [{
					required: true,
					message: $t("电费单价错误"),
					trigger: "blur",
					validator(_rule, value, callback) {
						if (!test.amount(value)) {
							callback(new Error("error"));
						} else {
							callback();
						}
					},
				}, ],
			},
			{
				label: $t("服务费"),
				value: "qbf",
				dw: $t("元"),
				defaultValue: "100",
				fl: "100",
				rule: [{
					required: true,
					message: $t("服务费错误"),
					trigger: "blur",
					validator(_rule, value, callback) {
						if (!test.amount(value)) {
							callback(new Error("error"));
						} else {
							callback();
						}
					},
				}, ],
			},
			{
				label: $t("时间设置"),
				value: "dfsj",
				dw: $t("分"),
				defaultValue: "60",
			},
		];
		return r;
	},
	function({
		formData
	}) {
		if (formData.type != 11) {
			return [];
		}
		const r = [{
				label: $t("电费单价"),
				value: "df",
				dw: $t("元/度"),
				defaultValue: "100",
				fl: 100,

				rules: [{
					required: true,
					message: $t("电费单价错误"),
					trigger: "blur",
					validator(_rule, value, callback) {
						if (!test.amount(value)) {
							callback(new Error("error"));
						} else {
							callback();
						}
					},
				}, ],
			},
			{
				label: $t("租置费用"),
				value: "qbf",
				defaultValue: "0",
				fl: "100",
				dw: $t("元/小时"),
			},
			{
				label: $t("免费时长"),
				value: "dfsj",
				defaultValue: "0",
				dw: $t("分"),
			},
		];
		return r;
	},
	function({
		formData
	}) {
		if (formData.type != 12) {
			return [];
		}
		const r = [];
		const list = [
			[{
					label: $t("尖峰"),
					value: "jdf",
				},
				{
					label: $t("尖峰服务费"),
					value: "jfff",
				},
				["jsjsh", "jsjsm", "jsjeh", "jsjem"],
			],
			[{
					label: $t("高峰"),
					value: "fdf",
				},
				{
					label: $t("高峰服务费"),
					value: "ffff",
				},
				["fsjsh", "fsjsm", "fsjeh", "fsjem"],
			],
			[{
					label: $t("平峰"),
					value: "pdf",
				},
				{
					label: $t("平峰服务费"),
					value: "pfff",
				},
				["psjsh", "psjsm", "psjeh", "psjem"],
			],
			[{
					label: $t("谷峰"),
					value: "gdf",
				},
				{
					label: $t("谷峰服务费"),
					value: "gfff",
				},
				["gsjsh", "gsjsm", "gsjeh", "gsjem"],
			],
		];
		list.forEach((e) => {
			r.push({
				value: e[0].value,
				label: `${e[0].label}${$t("电费")}`,
				dw: $t("元"),
				defaultValue: "0",
				fl: "100",
			}, {
				value: e[1].value,
				label: `${e[0].label}${$t("服务费")}`,
				dw: $t("元"),
				defaultValue: "0",
				fl: "100",
			});
			// ${e[3][0]}
			r.push({
				label: $t("添加档数"),
				type: "StepControl",
				min: 1,
				max: formData.gtype == 62 ? 2 : 5,
				span: 24,
				children: [{
					label: `${e[0].label}${$t("时间")}{0}`,
					// value: `${e[2][0]}${e[2][1]}${e[2][2]}${e[2][3]}{0}`,
					type: "timeslider",
					span: 24,
					modelValues: [{
							type: "h1",
							label: $t("时间") + "1",
							value: `${e[2][0]}{0}`
						},
						{
							type: "m1",
							label: $t("分钟") + "1",
							value: `${e[2][1]}{0}`
						},
						{
							type: "h2",
							label: $t("时间") + "2",
							value: `${e[2][2]}{0}`
						},
						{
							type: "m2",
							label: $t("分钟") + "2",
							value: `${e[2][3]}{0}`
						},
					],
				}, ],
			});
		});
		// {
		//   label: `${e[0].label}结束时间{0}`,
		//   value: ` ${e[2][2]}{0}`,
		//   type: "select",
		//   blur: ({ value, emit, item }) => {
		//     const vlist = value.split(":")
		//     const index = item.prop.match(/\d+/)[0]
		//     const setkey = {}
		//     setkey[`${e[2][2]}${index}`] = `${vlist[0]}`
		//     setkey[`${e[2][3]}${index}`] = `${vlist[1]}`
		//     emit("chang", setkey)
		//   },
		//   inputValue: ({ formData, item }) => {
		//     const index = item.prop.match(/\d+/)[0]
		//     if (formData[`${e[2][2]}${index}`] == undefined || formData[`${e[2][3]}${index}`] == undefined) {
		//       return "00:00"
		//     }
		//     return `${formData[`${e[2][2]}${index}`]}:${formData[`${e[2][3]}${index}`]}`
		//   },
		//   option: ({ item }) => {
		//     const r = []
		//     // 从前一个开始时间到24:00结束 每隔30分钟
		//     const index = item.prop.match(/\d+/)[0]
		//     const h = Number(formData[`${e[2][0]}${index}`])
		//     const m = Number(formData[`${e[2][1]}${index}`])
		//     const start = h * 60 + m
		//     console.log(start);

		//     for (let index = start; index <= 24 * 60; index += 30) {
		//       const h = Math.floor(index / 60)
		//       const m = index % 60
		//       const time = `${h < 10 ? '0' + h : h}:${m < 10 ? '0' + m : m}`
		//       r.push({ label: time, value: time })
		//     }

		//     return r
		//   }
		// },

		return r;
	},
	function({
		formData
	}) {
		if (formData.type != 14) {
			return [];
		}
		const r = [{
				label: $t("开锁余额"),
				value: "df",
				dw: $t("元"),
				defaultValue: "5000",
				fl: 100,
			},
			{
				label: $t("免占位费时长"),
				value: "jebd",
				dw: "分",
				defaultValue: "0",

				popover: $t("免占位费时长为新能源车进入车位未充电以及充电结束后计算的可免占位费的时长"),
			},
			{
				label: $t("占位费"),
				value: "qbf",
				dw: $t("元"),
				defaultValue: "500",
				fl: "100",
			},
			{
				label: $t("停车时长"),
				value: "dfsj",
				dw: $t("分"),
				defaultValue: "60",
			},
		];
		const list = [
			[{
					label: $t("尖峰"),
					value: "jdf",
				},
				{
					label: $t("尖峰服务费"),
					value: "jfff",
				},
				["jsjsh", "jsjsm", "jsjeh", "jsjem"],
			],
			[{
					label: $t("高峰"),
					value: "fdf",
				},
				{
					label: $t("高峰服务费"),
					value: "ffff",
				},
				["fsjsh", "fsjsm", "fsjeh", "fsjem"],
			],
			[{
					label: $t("平峰"),
					value: "pdf",
				},
				{
					label: $t("平峰服务费"),
					value: "pfff",
				},
				["psjsh", "psjsm", "psjeh", "psjem"],
			],
			[{
					label: $t("谷峰"),
					value: "gdf",
				},
				{
					label: $t("谷峰服务费"),
					value: "gfff",
				},
				["gsjsh", "gsjsm", "gsjeh", "gsjem"],
			],
		];
		list.forEach((e) => {
			r.push({
				value: e[0].value,
				label: `${e[0].label}${$t("电费")}`,
				dw: $t("元"),
				defaultValue: "0",
				fl: "100",
			}, {
				value: e[1].value,
				label: `${e[0].label}${$t("服务费")}`,
				dw: $t("元"),
				defaultValue: "0",
				fl: "100",
			});
			// ${e[3][0]}
			r.push({
				label: $t("添加档数"),
				type: "StepControl",
				min: 1,
				max: formData.gtype == 62 ? 2 : 3,
				span: 24,
				children: [{
					label: `${e[0].label}${$t("时间{0}")}`,
					// value: `${e[2][0]}${e[2][1]}${e[2][2]}${e[2][3]}{0}`,
					type: "timeslider",
					span: 24,
					modelValues: [{
							type: "h1",
							label: $t("时间") + "1",
							value: `${e[2][0]}{0}`
						},
						{
							type: "m1",
							label: $t("分钟") + "1",
							value: `${e[2][1]}{0}`
						},
						{
							type: "h2",
							label: $t("时间") + "2",
							value: `${e[2][2]}{0}`
						},
						{
							type: "m2",
							label: $t("分钟") + "2",
							value: `${e[2][3]}{0}`
						},
					],
				}, ],
			});
		});

		return r;
	},
	function({
		formData
	}) {
		if (formData.type != 15) {
			return [];
		}
		const r = [{
				label: $t("电费单价"),
				value: "dfsj",
				dw: $t("元/度"),
				defaultValue: "100",
				fl: 100,

				rule: [{
					required: true,
					message: $t("电费单价错误"),
					trigger: "blur",
					validator(_rule, value, callback) {
						if (!test.amount(value)) {
							callback(new Error("error"));
						} else {
							callback();
						}
					},
				}, ],
			},
			{
				label: $t("服务费"),
				value: "qbf",
				dw: $t("元/度"),
				defaultValue: "100",
				fl: "100",

				rule: [{
					required: true,
					message: $t("服务费错误"),
					trigger: "blur",
					validator(_rule, value, callback) {
						if (!test.amount(value)) {
							callback(new Error("error"));
						} else {
							callback();
						}
					},
				}, ],
			},
		];
		return r;
	},
];
const ChargeCaraddjson = [{
		label: $t("设备ID"),
		value: "gtel",
		rules: [{
			required: true,
			message: $t("请输入设备ID"),
			trigger: "blur",
		}, ],
		async blur({
			value,
			emit
		}) {
			console.log(value);
			if (value == "") {
				emit("chang", {
					gtype: ""
				});
				return;
			}
			const gtel = await request("/gtel", {
				gtel: value
			});
			const gtype = gtel.length > 0 ? gtel[0].gtype : "";
			emit("chang", {
				gtype
			});
			// gtype
		},
	},
	{
		label: $t("设备名称"),
		value: "mc",
	},
	{
		label: $t("地址"),
		value: "dz",
		type: "dz",
		modelValues: [
			// { type: "AreaCode", label: "区域编码", value: "AreaCode" },
			{
				type: "Address",
				label: $t("地址信息"),
				value: "dz"
			},
			{
				type: "mpt",
				label: $t("地图初始坐标"),
				value: "wz"
			},
		],
	},
	{
		label: $t("所属站点"),
		value: "pcs",
		type: "pcs",
		defaultValue: userstore.USearch.pcs,
	},
	{
		label: $t("品牌"),
		value: "pp",
		type: "select",
		option: [...defaultValue.pp],
		defaultValue: defaultValue.pp[0].prop,
	},
	...ChargeCartypes,
	{
		label: $t("平台电压"),
		value: "df1",
		type: "select",
		option: [{
				label: "750V/1000V",
				value: "0",
			},
			{
				label: "220V",
				value: "1",
			},
		],
		rules: [{
			required: true,
			message: $t("请选择平台电压"),
			trigger: "blur",
		}, ],
	},
	{
		label: $t("电桩功率"),
		value: "df2",
		type: "select",
		option: [{
				label: "7KW",
				value: "0",
			},
			{
				label: "14KW",
				value: "1",
			},
			{
				label: "120KW",
				value: "2",
			},
			{
				label: "240KW",
				value: "3",
			},
		],
		rules: [{
			required: true,
			message: $t("请选择电桩功率"),
			trigger: "blur",
		}, ],
	},
	{
		label: $t("备注"),
		value: "bz",
	},

	{
		label: $t("照片"),
		value: "zp",
		type: "img",
		limit: 3,
	},
	// {
	//   label: 'gtype',
	//   value: 'gtype',

	// },
	// {
	//   label: 'b_ask',
	//   value: 'b_ask',

	// }
];
const updefaultValue = {
	a1: "0",
	a2: "0",
	a3: "0",
	a4: "0",
	a5: "0",
	a6: "0",
	a7: "0",
	a8: "0",
	bz: "",
	df: "240",
	df1: "0",
	df2: "0",
	df3: "0",
	df4: "0",
	df5: "0",
	df6: "0",
	df7: "0",
	df8: "0",
	dfsj: "0.5",
	dz: "",
	qbf: "100",
	type: "2",
	zp: "",
};

// syl
// 站点管理员
const ChargeCareditjson = [{
		label: $t("所属站点"),
		value: "pcs",
		type: "pcs",
		defaultValue: userstore.USearch.pcs,
	},
	{
		label: $t("设备ID"),
		value: "gtel",
		attrs: {
			readonly: true,
		},
	},
	{
		label: $t("设备名称"),
		value: "mc",
	},

	{
		value: "sjc",
		label: $t("添加时间"),
		attrs: {
			readonly: true,
		},
	},
	{
		label: $t("设备状态"),
		value: "gzt",
		type: "select",
		option: [{
			label: $t("全部"),
			value: ""
		}, ...defaultValue.gzt],
		attrs: {
			disabled: true,
		},
	},
	function({
		formData
	}) {
		return [{
			label: $t("设备类型"),
			defaultValue: defaultValue.xtypelx(formData.xtype),
			attrs: {
				readonly: true,
			},
		}, ];
	},

	...ChargeCartypes,
	function({
		formData
	}) {
		return [{
			label: $t("运行时长"),
			defaultValue: timefn.getUTCtime(formData.sjc, "", 60 * 24 * 60) + $t("天"),
			attrs: {
				readonly: true,
			},
		}, ];
	},
	async function({
			formData
		}) {
			let Station = await requeststore.getRequest("/Station", {
				id: formData.pcs,
			});
			Station = Station.length > 0 ? Station[0] : {};
			return [{
					label: $t("负责人名称"),
					defaultValue: Station.glxm,
					attrs: {
						readonly: true,
					},
				},
				{
					label: $t("联系电话"),
					defaultValue: Station.gltel,
					attrs: {
						readonly: true,
					},
				},
			];
		},
		async function({
				formData
			}) {
				let gtel = await requeststore.getRequest("/gtel", {
					gtel: formData.gtel
				});
				gtel = gtel.length > 0 ? gtel[0] : {};
				return [{
					label: $t("物联网卡号"),
					defaultValue: gtel.gsim,
					attrs: {
						readonly: true,
					},
				}, ];
			},
			async function({
					formData
				}) {
					let Station = await requeststore.getRequest("/StationCar", {
						id: formData.pcs,
					});
					Station = Station.length > 0 ? Station[0] : {};
					console.log(Station, "StationStation");

					return [{
						label: $t("场地类型"),
						// value: 'StationType',
						type: "select",
						option: StationType,
						defaultValue: Station.StationType || "",
						attrs: {
							disabled: true,
						},
					}, ];
				}, {
					label: $t("品牌"),
					value: "pp",
					type: "select",
					option: [...defaultValue.pp],
					defaultValue: defaultValue.pp[0].prop,
				}, {
					label: $t("地址"),
					value: "dz",
					type: "dz",
					modelValues: [
						// { type: "AreaCode", label: "区域编码", value: "AreaCode" },
						{
							type: "Address",
							label: $t("地址信息"),
							value: "dz"
						},
						{
							type: "mpt",
							label: $t("地图初始坐标"),
							value: "wz"
						},
					],
				},
				async function({
						formData
					}) {
						let StationHD = await requeststore.getRequest("/StationHD", {
							id: formData.pcs,
						});
						StationHD = StationHD.length > 0 ? StationHD[0] : {};
						const xskey = formData.xtype == 8 ? "llfagentptcarz" : "llfagentptcarj";
						if (StationHD.llfagenttype == "0") {
							return [];
						}
						return [{
							label: $t("流量费"),
							// value: 'StationType',
							// type: "select",
							// option: StationType,
							defaultValue: StationHD[xskey],
							fl: 100,
							attrs: {
								disabled: true,
							},
							dw: `${$t("元")}/${StationHD.llfagenttype == 1 ? $t("每月") : t("每年")}`,
						}, ];
					},
					async function({
							formData,
							propsdata
						}) {

							if (!["2", "61", "62"].includes(String(formData.gtype))) {
								return [];
							}
							const list = [];
							const r = {
								label: t("第三方道闸"),
								value: "b_pm",
								defaultValue: "0",

								type: "select",
								option: [],
							};
							r.option =
								formData.type == 14 ? [{
										label: t("无道闸"),
										value: "0"
									},
									{
										label: t("科拓道闸"),
										value: "2"
									},
									{
										label: t("海康道闸"),
										value: "3"
									},
									{
										label: t("独立地锁"),
										value: "4"
									},
								] : [{
										label: t("无道闸"),
										value: "0"
									},
									{
										label: t("科拓道闸"),
										value: "2"
									},
									{
										label: t("海康道闸"),
										value: "3"
									},
								];
							list.push(r);
							if (formData.b_pm == "4") {
								let ChargeDS = [];
								if (propsdata.b_pm == 4) {
									ChargeDS = await requeststore.getRequest("/ChargeDS", {
										gtel: propsdata.gtel,
									});
								}
								const abc = [
									"A",
									"B",
									"C",
									"D",
									"E",
									"F",
									"G",
									"H",
									"I",
									"J",
									"K",
									"L",
									"M",
									"N",
								];
								for (let i = 0; i < propsdata.gls; i++) {
									let dqChargeDS = ChargeDS.find((e) => {
										return e.gtel == formData.gtel && e.td == i + 1;
									});
									dqChargeDS = dqChargeDS || {};
									const a = abc[i];
									list.push({
										label: t(`${a}枪地锁桩号`),
										value: `gtelds${i + 1}`,
										defaultValue: dqChargeDS.gtelds || "",
									}, {
										label: t(`${a}枪地锁桩号`),
										value: `tdds${i + 1}`,

										defaultValue: dqChargeDS.tdds || "",
									});
								}
							}

							return list;
						}, {
							label: t("平台电压"),
							value: "df1",
							type: "select",
							option: [{
									label: "750V/1000V",
									value: "0",
								},
								{
									label: "220V",
									value: "1",
								},
							],
							rules: [{
								required: true,
								message: t("请选择平台电压"),
								trigger: "blur",
							}, ],
						}, {
							label: t("电桩功率"),
							value: "df2",
							type: "select",
							option: [{
									label: "7KW",
									value: "0",
								},
								{
									label: "14KW",
									value: "1",
								},
								{
									label: "120KW",
									value: "2",
								},
								{
									label: "240KW",
									value: "3",
								},
							],
							rules: [{
								required: true,
								message: t("请选择电桩功率"),
								trigger: "blur",
							}, ],
						}, {
							label: t("备注"),
							value: "bz",
						},

						{
							label: t("照片"),
							value: "zp",
							type: "img",
							limit: 3,
						},
];
// 验证数据是否合法
function checkdata(data) {
	const r = [];
	if (!(data.type == "12" || data.type == "14")) {
		return r;
	}
	const formdatakeys = [
		["jsjsh1", "jsjsm1", "jsjeh1", "jsjem1"],
		["jsjsh2", "jsjsm2", "jsjeh2", "jsjem2"],
		["jsjsh3", "jsjsm3", "jsjeh3", "jsjem3"],
		["fsjsh1", "fsjsm1", "fsjeh1", "fsjem1"],
		["fsjsh2", "fsjsm2", "fsjeh2", "fsjem2"],
		["fsjsh3", "fsjsm3", "fsjeh3", "fsjem3"],
		["psjsh1", "psjsm1", "psjeh1", "psjem1"],
		["psjsh2", "psjsm2", "psjeh2", "psjem2"],
		["psjsh3", "psjsm3", "psjeh3", "psjem3"],
		["gsjsh1", "gsjsm1", "gsjeh1", "gsjem1"],
		["gsjsh2", "gsjsm2", "gsjeh2", "gsjem2"],
		["gsjsh3", "gsjsm3", "gsjeh3", "gsjem3"],
	];
	const times = [];
	for (let i = 0; i < formdatakeys.length; i++) {
		const formdatakey = formdatakeys[i];
		let t1 = data[formdatakey[0]] ? data[formdatakey[0]] : "0";
		let t2 = data[formdatakey[1]] ? data[formdatakey[1]] : "0";
		let t3 = data[formdatakey[2]] ? data[formdatakey[2]] : "0";
		let t4 = data[formdatakey[3]] ? data[formdatakey[3]] : "0";
		if (t1 == "0" && t2 == "0" && t3 == "0" && t4 == "0") {
			continue;
		}
		// t1不足两位补0
		if (t1.length == 1) {
			t1 = "0" + t1;
		}
		// t2不足两位补0
		if (t2.length == 1) {
			t2 = "0" + t2;
		}
		// t3不足两位补0
		if (t3.length == 1) {
			t3 = "0" + t3;
		}
		// t4不足两位补0
		if (t4.length == 1) {
			t4 = "0" + t4;
		}
		times.push({
			sjs: t1 + ":" + t2,
			sje: t3 + ":" + t4,
		});
	}
	console.log(times, "11");

	if (times.length == 0) {
		r.push(t("没有设置时间段"));
		return r;
	}
	// 判断times是否有重复和交叉和是否占满24小时
	const times2 = [];
	for (let i = 0; i < times.length; i++) {
		const time = times[i];
		const sjs = time.sjs;
		const sje = time.sje;
		const sjs2 = sjs.replace(":", "");
		const sje2 = sje.replace(":", "");
		if (Number(sjs2) >= Number(sje2)) {
			r.push(t("时间段") + sjs + "-" + sje + t("开始时间大于结束时间"));
		}
		times2.push({
			sjsxs: sjs,
			sjs: sjs2,
			sje: sje2,
			sjexs: sje,
		});
	}
	times2.sort((a, b) => {
		return Number(a.sjs) - Number(b.sjs);
	});

	for (let i = 0; i < times2.length - 1; i++) {
		const time = times2[i];
		const time2 = times2[i + 1];
		if (Number(time.sje) > Number(time2.sjs)) {
			r.push(
				t("时间段") +
				time.sjsxs +
				"-" +
				time.sjexs +
				t("和") +
				time2.sjsxs +
				"-" +
				time2.sjexs +
				t("交叉")
			);
		} else if (time.sje != time2.sjs) {
			r.push(
				t("时间段") +
				time.sjsxs +
				"-" +
				time.sjexs +
				t("和") +
				time2.sjsxs +
				"-" +
				time2.sjexs +
				t("不连续")
			);
		}
	}
	const t1 = times2[0];
	const t2 = times2[times2.length - 1];
	if (t1.sjs != "0000" || t2.sje != "2400") {
		r.push(t("时间段没有占满24小时"));
	}
	return r;
}

let states = [{
		label: t("桩号"),
		value: "gtel",
		attrs: {
			disabled: true
		}
	},
	{
		label: $t(t("设备状态")),
		value: "gzt",
		type: "select",
		option: [...defaultValue.gzt],
		attrs: {
			disabled: true
		},
	},
	{
		label: t("添加时间"),
		value: "sjc",
		attrs: {
			disabled: true
		}
	},
];
const state1 = [
	function({
		formData
	}) {
		const r =
			formData.gxh == 0 || !formData.gxh ?
			t("无") :
			formData.gxh < 20 ?
			`${t("弱")}${formData.gxh}` :
			formData.gxh <= 25 ?
			`${t("中")}${formData.gxh}` :
			`${t("强")}${formData.gxh}`;
		return [{
			label: t("信号强度"),
			defaultValue: r,
			attrs: {
				disabled: true
			},
		}, ];
	},
	function({
		formData
	}) {
		const r = [{
			label: formData.gzt == 0 ? t("离线时间") : t("更新时间"),
			value: "sjup",
			attrs: {
				disabled: true
			},
		}, ];
		return r;
	},

	{
		label: t("烟感状态"),
		value: "gyg",
		type: "select",
		option: [...defaultValue.gyg],
		attrs: {
			disabled: true
		},
	},
	{
		label: t("设备温度"),
		value: "gwd",
		dw: "℃",
		fl: "10",
		attrs: {
			disabled: true
		},
	},
	{
		label: t("抄表电量"),
		value: "dbdf",
		dw: "A",
		attrs: {
			disabled: true
		},
	},
	{
		label: t("硬币收入"),
		value: "tbsum",
		attrs: {
			disabled: true
		},
	},
	{
		label: t("硬件版本"),
		value: "yjbb",
		attrs: {
			disabled: true
		},
	},
	{
		label: t("软件版本"),
		value: "rjbb",
		attrs: {
			disabled: true
		},
	},
];

// const state2 = [
//   {
//     callback: (data: { gzt: number; }) => {
//       const r = [
//         {
//           label: data.gzt == 0 ? '离线时间' : '更新时间',
//           value: 'sjup',
//           disabled: true,
//         },
//       ]
//       return r
//     },
//   },
//   {
//     label: 'A表电量',
//     value: 'gcdl1',
//     dw: 'A',
//   },
//   {
//     label: 'B表电量',
//     value: 'gcdl2',
//     dw: 'A',
//   },
// ]
// //
// const state3 = [
//   { label: '剩余电流', value: '剩余电流', defaultValue: '0' },
//   { label: '故障电弧', value: '故障电弧', defaultValue: '无' },
//   { label: '相电流', value: '相电流', defaultValue: '0' },
//   { label: '脱钩联动', value: '脱钩联动', defaultValue: '无' },
//   { label: '故障联动', value: '故障联动', defaultValue: '无' },
//   { label: '报警联动', value: '报警联动', defaultValue: '无' },
//   { label: '联动输入报警', value: '联动输入报警', defaultValue: '无' },
// ]
// const state4 = [
//   {
//     callbackasync: async (data: { [x: string]: number; }) => {
//       const r = []
//       let disabledfalg = true

//       if (
//         [4, 3, 8, 14, 15].find((e) => {
//           return store.state.user.token.utype == e
//         }) ||
//         (store.state.user.token.utype == 0 && store.state.user.token.udj == 0)
//       ) {
//         disabledfalg = false
//       }
//       const isqc = defaultValue.isqc(data)
//       for (let i = 1; i <= data['gls']; i++) {
//         let glztoption = deepClone(defaultValue.glzt)
//         if (isqc) {
//           const cqzd = Number(i) + 2
//           const v =
//             data[`gcdl${cqzd}`] == 1
//               ? '已插枪'
//               : data[`gcdl${cqzd}`] == 2
//                 ? '急停按钮被按下'
//                 : '未插枪'
//           glztoption = glztoption.map((e: { value: number; label: string; }) => {
//             if (e.value == 0) {
//               e.label = v
//             }
//             return e
//           })
//         }

//         r.push({
//           label: `第${i}路`,
//           value: `glzt${i}`,
//           type: 'select',
//           option: [...glztoption],
//           disabled: disabledfalg,
//           typeurl: '/ChargeCarSysedt',
//           typevalue: `glzt${i}`,
//           upvalue: `gzt`,
//           uodata: { td: i },
//         })
//       }

//       if (
//         [4, 3, 8, 14].find((e) => {
//           return store.state.user.token.utype == e
//         }) ||
//         (store.state.user.token.utype == 0 && store.state.user.token.udj == 0)
//       ) {
//         r.push({
//           label: '支付配置',
//           value: 'b_use',
//           type: 'select',
//           option: [...defaultValue.b_use],
//           typeurl: '/ChargeCarQR',
//           typevalue: 'b_use',
//           upvalue: `b_use`,
//         })

//         // data.b_cmzt=
//         r.push({
//           label: '设备配置',
//           value: 'b_cmzt',
//           type: 'select',
//           option: [
//             { label: '不显示', value: '0' },
//             { label: '默认显示', value: '1' },
//             {
//               label: '默认选中',
//               value: '2',
//             },
//           ],
//           typeurl: '/ChargeCfgedt',
//           typevalue: 'b_cmzt',
//           upvalue: `b_cmzt`,
//         })
//         r.push({
//           label: '银行支付',
//           value: 'zftype',
//           type: 'select',
//           option: [
//             { label: '关闭银行支付', value: '0' },
//             { label: '打开海康云南农行支付', value: '1' },
//             { label: '打开山东众德农行支付', value: '2' },
//             { label: '打开江苏农业银行支付', value: '7' },
//             { label: '打开上海沪慧云闪付', value: '3' },
//             { label: '打开赣州美天云闪付', value: '4' },
//             { label: '打开交通银行数字货币支付', value: '5' },
//             { label: '打开赣州云闪付小程序', value: '6' },
//             { label: '泰州姜堰农行支付', value: '8' },
//           ],
//           typeurl: '/ChargeCfgedtBank',
//           typevalue: 'banktype',
//           upvalue: `banktype`,
//         })
//         // ChargeCfgedtBank
//       }
//       // ChargeCfgedt
//       return r
//     },
//   },
// ]

// states = states
//   .concat(
//     state1.map((e) => {
//       e.disabled = true
//       e.if = {
//         zhierror: [{ value: 'gtype', zhi: ['61', '62'] }],
//       }
//       return e
//     })
//   )
//   .concat(
//     state2.map((e) => {
//       e.disabled = true
//       e.if = {
//         zhi: [{ value: 'gtype', zhi: ['61', '62'] }],
//       }
//       return e
//     })
//   )
//   .concat(
//     state3
//       .filter(() => {
//         return store.getters['upw/b_info']
//       })
//       .map((e) => {
//         e.disabled = true
//         e.if = {
//           zhi: [{ value: 'UPW_b_info', zhi: ['1'] }],
//         }
//         return e
//       })
//   )
//   .concat(state4)
const state2 = [
	function({
		formData
	}) {
		return [{
			label: formData.gzt == 0 ? t("离线时间") : t("更新时间"),
			value: "sjup",
			attrs: {
				disabled: true
			},
		}, ];
	},
	{
		label: t("A表电量"),
		value: "gcdl1",
		dw: "A",
		attrs: {
			disabled: true
		},
	},
	{
		label: t("B表电量"),
		value: "gcdl2",
		dw: "A",
		attrs: {
			disabled: true
		},
	},
];
const state4 = [
	function({
		formData
	}) {
		let disabledfalg = true;

		if (
			[4, 3, 8, 14, 15].find((e) => {
				return userstore.USearch.utype == e;
			}) ||
			(userstore.USearch.utype == 0 && userstore.USearch.udj == 0)
		) {
			disabledfalg = false;
		}

		const isqc = defaultValue.isqc(formData);
		const r = [];
		for (let i = 1; i <= formData["gls"]; i++) {
			let glztoption = defaultValue.glzt;
			if (isqc) {
				const cqzd = Number(i) + 2;
				const v =
					formData[`gcdl${cqzd}`] == 1 ?
					t("已插枪") :
					formData[`gcdl${cqzd}`] == 2 ?
					t("B急停按钮被按下") :
					t("未插枪");
				glztoption = glztoption.map((e) => {
					if (e.value == 0) {
						e.label = v;
					}
					return e;
				});
			}

			r.push({
				label: t(`第${i}路`),
				value: `glzt${i}`,
				type: "select",
				option: [...glztoption],
				disabled: disabledfalg,
				typeurl: "/ChargeCarSysedt",
				typevalue: `glzt${i}`,
				upvalue: `gzt`,
				uodata: {
					td: i
				},
			});
		}

		if (
			[4, 3, 8, 14].find((e) => {
				return userstore.USearch.utype == e;
			}) ||
			(userstore.USearch.utype == 0 && userstore.USearch.udj == 0)
		) {
			r.push({
				label: t("支付配置"),
				value: "b_use",
				type: "select",
				option: [...defaultValue.b_use],
				typeurl: "/ChargeCarQR",
				typevalue: "b_use",
				upvalue: `b_use`,
			});

			// data.b_cmzt=
			r.push({
				label: t("设备配置"),
				value: "b_cmzt",
				type: "select",
				option: [{
						label: t("不显示"),
						value: "0"
					},
					{
						label: t("默认显示"),
						value: "1"
					},
					{
						label: t("默认选中"),
						value: "2",
					},
				],
				typeurl: "/ChargeCfgedt",
				typevalue: "b_cmzt",
				upvalue: `b_cmzt`,
			});
			r.push({
				label: t("银行支付"),
				value: "zftype",
				type: "select",
				option: [{
						label: t("关闭银行支付"),
						value: "0"
					},
					{
						label: t("打开海康云南农行支付"),
						value: "1"
					},
					{
						label: t("打开山东众德农行支付"),
						value: "2"
					},
					{
						label: t("打开江苏农业银行支付"),
						value: "7"
					},
					{
						label: t("打开上海沪慧云闪付"),
						value: "3"
					},
					{
						label: t("打开赣州美天云闪付"),
						value: "4"
					},
					{
						label: t("打开交通银行数字货币支付"),
						value: "5"
					},
					{
						label: t("打开赣州云闪付小程序"),
						value: "6"
					},
					{
						label: t("泰州姜堰农行支付"),
						value: "8"
					},
				],
				typeurl: "/ChargeCfgedtBank",
				typevalue: "banktype",
				upvalue: `banktype`,
			});
		}
		return r;
	},
];

states.push(async function({
	propsdata,
	formData
}) {
	if (["61", "62"].includes(String(formData.gtype))) {
		return [];
	}
	let r = [];
	for (let index = 0; index < state1.length; index++) {
		const e = state1[index];
		if (typeof e == "function") {
			r = r.concat(
				await e({
					propsdata,
					formData,
				})
			);
		} else {
			r.push(e);
		}
	}
	console.log(r);

	return r;
});
states.push(async function({
	propsdata,
	formData
}) {
	if (!["61", "62"].includes(String(formData.gtype))) {
		return [];
	}
	let r = [];
	for (let index = 0; index < state2.length; index++) {
		const e = state2[index];
		if (typeof e == "function") {
			r = r.concat(
				await e({
					propsdata,
					formData,
				})
			);
		} else {
			r.push(e);
		}
	}
	console.log(r);

	return r;
});
states = states.concat(state4);
const addpl = deepClone(ChargeCaraddjson).map((e) => {
	if (e.prop == "gtel") {
		e.type = "excel";
		e.span = 24;
	}
	return e;
});
const CdzsbpzglinfoSearchjson = [{
		label: t("设备序列号"),
		value: "gtel",
	},
	{
		label: t("充电桩名称"),
		value: "cdzname",
		rule: [{
			required: true,
			message: t("请填写充电桩名称"),
			trigger: "blur"
		}],
	},
	{
		label: t("型号"),
		value: "xh",
	},
	{
		label: $t("设备类型"),
		value: "sblx",
		type: "select",
		option: [{
				label: t("直流充电桩"),
				value: "1"
			},
			{
				label: t("交流充电桩"),
				value: "2"
			},
			{
				label: t("分体式充电桩"),
				value: "3"
			},
		],
		defaultValue: "1",
	},
	{
		label: t("功率"),
		value: "gl",
	},
	{
		label: t("枪数"),
		value: "qs",
	},
	{
		label: t("输出电流"),
		value: "scdl",
	},
	{
		label: t("通信方式"),
		value: "txfs",
	},
	{
		label: t("屏幕"),
		value: "pm",
	},
	{
		label: t("宣传图"),
		value: "xctpic",
		type: "img",
	},
];
export default {
	addpl,
	checkdata,
	ChargeCartypes,
	states,
	ChargeCarsearchjson,
	ChargeCaraddjson,
	ChargeCareditjson,
	updefaultValue,
	CdzsbpzglinfoSearchjson,
};